package com.beyond.controller;


import com.beyond.constant.ApplicationConstant;
import com.beyond.service.UserService;
import com.beyond.vo.BaseRespVO;
import com.beyond.vo.PaginaionVO;
import com.beyond.vo.safe.FireVO;
import com.beyond.vo.safe.SafeCapCountVO;
import com.beyond.vo.safe.SafecapVO;
import com.beyond.vo.user.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "user")
public class UserController {
	private static Logger logger= Logger.getLogger(UserController.class);
	
	@Autowired
	private UserService userServiceImpl;


/**
	 * 
	* @Title: insertUser 
	* @Description: 增加用户
	* @param reqVO
	* @return BaseRespVO
	 */
	@ResponseBody
	@RequestMapping(value = "v1/add")
	public BaseRespVO insertUser(@RequestBody UserAddReqVO reqVO) {
		try {
			return userServiceImpl.insertUser(reqVO);
		} catch (Exception e) {
			BaseRespVO respVO = new BaseRespVO();
			e.printStackTrace();
			respVO.setMsg(e.getMessage());
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(respVO.getMsg());
			return respVO;
		}
	}
	

  /**
    *
    * @Title: updateUserLabel 
    * @Description: 修改用户标签
    * @param reqVO
    * @return BaseRespVO
     */
	@ResponseBody
	@RequestMapping(value = "v1/updateuser")
	public BaseRespVO updateUser(@RequestBody UserAddReqVO reqVO){
		try {
			return userServiceImpl.updateUser(reqVO);
		} catch (Exception e) {
			e.printStackTrace();
			BaseRespVO respVO = new BaseRespVO();
			respVO.setMsg(e.getMessage());
			respVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(respVO.getMsg());
			return respVO;
		}
	}

    /**
     *
     * @Title: deleteUser
     * @Description: 修改用户标签
     * @param reqVO
     * @return BaseRespVO
     */
    @ResponseBody
    @RequestMapping(value = "v1/deleteUser")
    public BaseRespVO deleteUser(@RequestBody UserAddReqVO reqVO){
        try {
            return userServiceImpl.deleteUser(reqVO);
        } catch (Exception e) {
            e.printStackTrace();
            BaseRespVO respVO = new BaseRespVO();
            respVO.setMsg(e.getMessage());
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            logger.error(respVO.getMsg());
            return respVO;
        }
    }

	/**
	 * @Title: selectUserList
	 * @Description: 查询用户列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<UserAddReqVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectUserList")
	public PaginaionVO<UserAddReqVO> selectUserList(@RequestBody UserAddReqVO req, int page, int pageSize){
		try {
			return userServiceImpl.selectUserList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<UserAddReqVO> paginaionVO = new PaginaionVO<UserAddReqVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

  /**
	 * @Title: selectPersonList
	 * @Description: 查询人员列表
	 * @param reqVO
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<UserLabelVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectPersonList")
	public PaginaionVO<PersonVO> selectPersonList(@RequestBody PersonVO reqVO, int page, int pageSize){
		try {
			return userServiceImpl.selectPersonList(reqVO,page,pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<PersonVO> paginaionVO = new PaginaionVO<PersonVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

	/**
	 * @Title: selectPersonAgeCount
	 * @Description: 查询人员年龄分布
	 * @param req
	 * @return PaginaionVO<PersonAgeCountVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectPersonAgeCount")
	public PaginaionVO<PersonAgeCountVO> selectPersonAgeCount(@RequestBody PersonAgeCountVO req){
		try {
			return userServiceImpl.selectPersonAgeCount(req);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<PersonAgeCountVO> paginaionVO = new PaginaionVO<PersonAgeCountVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

	/**
	 * @Title: selectPersonSourceCount
	 * @Description: 查询人员来源分布
	 * @param req
	 * @return PaginaionVO<PersonSourceCountVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectPersonSourceCount")
	public PaginaionVO<PersonSourceCountVO> selectPersonSourceCount(@RequestBody PersonSourceCountVO req, int page, int pageSize){
		try {
			return userServiceImpl.selectPersonSourceCount(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<PersonSourceCountVO> paginaionVO = new PaginaionVO<PersonSourceCountVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

	/**
	 * @Title: selectRecordList
	 * @Description: 查询记录列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<RecordVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectRecordList")
	public PaginaionVO<RecordVO> selectRecordList(@RequestBody RecordVO req, int page, int pageSize){
		try {
			return userServiceImpl.selectRecordList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<RecordVO> paginaionVO = new PaginaionVO<RecordVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

	/**
	 * @Title: selectRecordCount
	 * @Description: 人员情况汇总列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<RecordCountVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectRecordCount")
	public PaginaionVO<RecordCountVO> selectRecordCount(@RequestBody RecordCountVO req, int page, int pageSize){
		try {
			return userServiceImpl.selectRecordCount(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<RecordCountVO> paginaionVO = new PaginaionVO<RecordCountVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

	/**
	 * @Title: selectWorkingTimeList
	 * @Description: 查询工作时长记录列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<WorkingTimeVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectWorkingTimeList")
	public PaginaionVO<WorkingTimeVO> selectWorkingTimeList(@RequestBody WorkingTimeVO req,int page,int pageSize){
		PaginaionVO<WorkingTimeVO> respVo;
		try {
			logger.debug("url:user/v1/selectWorkingTimeList,parameter:" + req.toString() + ";page:" + page + ";pageSize:"+ pageSize);
			// 默认分页参数
			if (page == 0) {
				page = 1;
			}
			if (pageSize == 0) {
				pageSize = 10;
			}
			respVo = userServiceImpl.selectWorkingTimeList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			respVo = new PaginaionVO<WorkingTimeVO>();
			respVo.setMsg(e.getMessage());
			respVo.setResult(ApplicationConstant.RESULT_FALTURE);
		}
		return respVo;
	}

	/**
	 * @Title: selectSafeCapList
	 * @Description: 查询安全帽佩戴检测列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<SafecapVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectSafeCapList")
	public PaginaionVO<SafecapVO> selectSafeCapList(@RequestBody SafecapVO req, int page, int pageSize){
		PaginaionVO<SafecapVO> respVo;
		try {
			logger.debug("url:user/v1/selectSafeCapList,parameter:" + req.toString() + ";page:" + page + ";pageSize:"+ pageSize);
			// 默认分页参数
			if (page == 0) {
				page = 1;
			}
			if (pageSize == 0) {
				pageSize = 10;
			}
			respVo = userServiceImpl.selectSafeCapList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			respVo = new PaginaionVO<SafecapVO>();
			respVo.setMsg(e.getMessage());
			respVo.setResult(ApplicationConstant.RESULT_FALTURE);
		}
		return respVo;
	}

	/**
	 * @Title: selectFireList
	 * @Description: 查询火灾预警列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<FireVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectFireList")
	public PaginaionVO<FireVO> selectFireList(@RequestBody FireVO req, int page, int pageSize){
		PaginaionVO<FireVO> respVo;
		try {
			logger.debug("url:user/v1/selectFireList,parameter:" + req.toString() + ";page:" + page + ";pageSize:"+ pageSize);
			// 默认分页参数
			if (page == 0) {
				page = 1;
			}
			if (pageSize == 0) {
				pageSize = 10;
			}
			respVo = userServiceImpl.selectFireList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			respVo = new PaginaionVO<FireVO>();
			respVo.setMsg(e.getMessage());
			respVo.setResult(ApplicationConstant.RESULT_FALTURE);
		}
		return respVo;
	}

	/**
	 * @Title: selectHistoryAlarmList
	 * @Description: 查询历史报警查询列表
	 * @param req
	 * @param page
	 * @param pageSize
	 * @return PaginaionVO<FireVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectHistoryAlarmList")
	public PaginaionVO<FireVO> selectHistoryAlarmList(@RequestBody FireVO req, int page, int pageSize){
		PaginaionVO<FireVO> respVo;
		try {
			logger.debug("url:user/v1/selectHistoryAlarmList,parameter:" + req.toString() + ";page:" + page + ";pageSize:"+ pageSize);
			// 默认分页参数
			if (page == 0) {
				page = 1;
			}
			if (pageSize == 0) {
				pageSize = 10;
			}
			respVo = userServiceImpl.selectHistoryAlarmList(req, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			respVo = new PaginaionVO<FireVO>();
			respVo.setMsg(e.getMessage());
			respVo.setResult(ApplicationConstant.RESULT_FALTURE);
		}
		return respVo;
	}

	/**
	 * @Title: selectSafeCatCount
	 * @Description: 查询安全帽佩戴检测统计
	 * @param req
	 * @return PaginaionVO<SafeCapCountVO>
	 */
	@ResponseBody
	@RequestMapping(value = "v1/selectSafeCatCount")
	public PaginaionVO<SafeCapCountVO> selectSafeCatCount(@RequestBody SafeCapCountVO req){
		try {
			return userServiceImpl.selectSafeCatCount(req);
		} catch (Exception e) {
			e.printStackTrace();
			PaginaionVO<SafeCapCountVO> paginaionVO = new PaginaionVO<SafeCapCountVO>();
			paginaionVO.setMsg(e.getMessage());
			paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
			logger.error(paginaionVO.getMsg());
			return paginaionVO;
		}
	}

    /**
     * @Title: selectFireAlarmCount
     * @Description: 查询所有火灾预警次数统计
     * @param req
     * @return PaginaionVO<SafeCapCountVO>
     */
    @ResponseBody
    @RequestMapping(value = "v1/selectFireAlarmCount")
    public PaginaionVO<SafeCapCountVO> selectFireAlarmCount(@RequestBody SafeCapCountVO req){
        try {
            return userServiceImpl.selectFireAlarmCount(req);
        } catch (Exception e) {
            e.printStackTrace();
            PaginaionVO<SafeCapCountVO> paginaionVO = new PaginaionVO<SafeCapCountVO>();
            paginaionVO.setMsg(e.getMessage());
            paginaionVO.setResult(ApplicationConstant.RESULT_FALTURE);
            logger.error(paginaionVO.getMsg());
            return paginaionVO;
        }
    }


}

